<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "shbb_person".
 *
 * @property integer $id
 * @property string $name
 * @property string $tel
 * @property string $mobile
 * @property string $email
 * @property string $identity_card
 * @property string $identity_photo
 * @property integer $land_id
 * @property integer $park_id
 * @property integer $company_id
 * @property integer $is_assigned
 *
 * @property Company[] $shbbCompanies
 * @property Land[] $shbbLands
 * @property Park[] $shbbParks
 * @property Park[] $shbbParks0
 * @property Company $company
 * @property Land $land
 * @property Park $park
 * @property User[] $users
 */
class Person extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shbb_person';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['land_id', 'park_id', 'company_id'], 'integer'],
            [['name', 'tel', 'mobile', 'email', 'identity_card', 'identity_photo'], 'string', 'max' => 255],
            ['email', 'email'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '姓名',
            'tel' => '联系电话',
            'mobile' => '手机',
            'email' => '电子邮箱',
            'identity_card' => '身份证号',
            'identity_photo' => '身份证照片',
            'land_id' => '所属地块',
            'park_id' => '所属园区',
            'company_id' => '所属公司',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbCompanies()
    {
        return $this->hasMany(Company::className(), ['pricipal_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbLands()
    {
        return $this->hasMany(Land::className(), ['pricipal_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbParks()
    {
        return $this->hasMany(Park::className(), ['contact_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbParks0()
    {
        return $this->hasMany(Park::className(), ['pricipal_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCompany()
    {
        return $this->hasOne(Company::className(), ['id' => 'company_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLand()
    {
        return $this->hasOne(Land::className(), ['id' => 'land_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPark()
    {
        return $this->hasOne(Park::className(), ['id' => 'park_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return $this->hasMany(User::className(), ['person_id' => 'id']);
    }
}
